clear all
set type double
global DAYS = "30 60 90 120 180"
cap program drop varlabeling_unification
program varlabeling_unification
	args buyer
	foreach days in $DAYS {
	    cap drop mean*blog`days'	/* meanblogx is var to generate normalized backlog: rblog*/
		bys firm_id: egen mean_blog`days' = mean(blog`days')			
		bys firm_id: egen mean_lnblog`days' = mean(lnblog`days')
	}
	qui bys firm_id: egen N_won = total(winner)			
	qui egen contract_tg = tag(contract_id)
	foreach v in reserve_thd winbid_thd win_bid_pct N_bids lowbid_thd est_mil low_bid_pct {
		cap replace `v' = . if contract_tg != 1
	}
	cap drop firm_tg
	qui egen firm_tg = tag(firm_id)
	foreach v in N_participations N_won{
		replace `v' = . if firm_tg != 1
	}
	foreach d in $DAYS{
		qui replace mean_lnblog`d' = . if firm_tg != 1
		qui replace mean_blog`d' = . if firm_tg != 1
		if "`buyer'" == "mongolia" {
		    replace mean_blog`d' = mean_blog`d' / 1000000
		}
		else if "`buyer'" == "indonesia" {
		    replace mean_blog`d' = mean_blog`d' / 1000000		
		}
		else{
		    replace mean_blog`d' = mean_blog`d' / 1000
		}
	}
	label var winbid_thd "\raisebox{-2.2mm}[0mm][0mm]{Winning Bid}"
	label var win_bid_pct "\raisebox{-2.2mm}[0mm][0mm]{WinBid / Reserve}"
	cap label var low_bid_pct "\raisebox{-2.2mm}[0mm][0mm]{Low Bid / Reserve}"
	label var N_bids "\raisebox{-2.2mm}[0mm][0mm]{\# Bids}"
	label var N_participations "\raisebox{-2.2mm}[0mm][0mm]{\# Participation}"
	label var N_won "\raisebox{-2.2mm}[0mm][0mm]{\# Winning}"
	label var reserve_thd "\raisebox{-2.2mm}[0mm][0mm]{Reserve}"
	label var lowbid_thd "\raisebox{-2.2mm}[0mm][0mm]{Low bid}"
	label var est_mil "\raisebox{-2.2mm}[0mm][0mm]{Engineer's Estimate}"
	label var lowbid_thd "\raisebox{-2.2mm}[0mm][0mm]{Low bid}"
	if "`buyer'" == "indonesia"{
	    label var lowbid_thd "\raisebox{-2.2mm}[0mm][0mm]{Low bid (Million)}"
		label var reserve_thd "\raisebox{-2.2mm}[0mm][0mm]{Reserve (Million)}"
	}

	foreach days0 in $DAYS {
		label var mean_lnblog`days0' "\raisebox{-2.2mm}[0mm][0mm]{`days0'-Day Log Backlog}"
		label var mean_blog`days0' "\raisebox{-2.2mm}[0mm][0mm]{`days0'-Day Backlog}"
	}
end





/* Indonesia */
	use ../Data/indonesia/xyz.dta, clear
	rename _merge _merge0
	tempfile tempf0
	preserve
		use "../Data/Indonesia/all_project_table.dta", clear
		keep uniq_pid classification nama_paket_pekerjaan
		qui count
		local Length = r(N)
		forvalues i = 1(1)`Length'{
		    local exp0 = ustrregexra(strlower(classification[`i'])," $","")
			local exp0 = ustrregexra("`exp0'", "\, ", "\,")
		    qui replace classification = "`exp0'" if _n == `i'
		}
		save `tempf0', replace
	restore
	merge m:1 uniq_pid using `tempf0'

	keep if z_konsultan == 0
	
	preserve
		/* Type of Projects: Indonesia */
		gen lowbid = z_bid_rank == 1
		keep if lowbid == 1
		bys classification: gen classification_N = _N 
		bys classification: egen Amount = total(z_bid)
		egen classification_T = tag(lowbid classification)
		gen total_number_contracts = _N
		egen total_contract_amount = total(z_bid) 
		gen classification_R = classification_N / total_number_contracts
		gen Amount_R = Amount / total_contract_amount 
		gsort -classification_N
		insobs 2, before(1)
		replace classification_T = 1 if _n <= 2
		replace classification_R = 1 if _n == 1
		replace Amount_R = 1 if _n == 1
		replace Amount = total_contract_amount[3] if _n == 1
		replace classification_N = total_number_contracts[3] if _n == 1
		gen blank = "Work" if _n == 1
		gen share = "("+strofreal(classification_R* 100, "%6.1f")+"\%)" if _n != 2
		gen N_str = strofreal(classification_N, "%8.0gc")  if _n != 2
		gen Amount_R_str = "("+strofreal(Amount_R * 100, "%6.1f")+"\%)" if _n != 2
		gen Amount_str = strofreal(round(Amount/1000000), "%12.0gc") if _n != 2
		keep if classification_T == 1
		
		keep classification share N_str Amount_R_str Amount_str blank
		
		gen classification_en = classification
		replace classification_en = ustrregexra(classification_en, "^sipil$","civil")
		replace classification_en = ustrregexra(classification_en, "^jalan dan jembatan$","roads and bridges")
		replace classification_en = ustrregexra(classification_en, "^tata lingkungan$","environmental planning")
		replace classification_en = ustrregexra(classification_en, "^arsitektur$","architecture")
		replace classification_en = ustrregexra(classification_en, "^drainase dan jaringan pengairan$","drainage and irrigation network")
		replace classification_en = ustrregexra(classification_en, "^jalan,jembatan,landasan dan lokasi pengeboran darat$","roads, bridges, runways, and onshore drilling sites")
		replace classification_en = ustrregexra(classification_en, "^alat$","equipment")
		replace classification_en = ustrregexra(classification_en, "^bidang sipil$","civil field")
		replace classification_en = ustrregexra(classification_en, "^bidang sipil sub bidang jalan dan jembatan$","civil field, subfield of roads and bridges")
		replace classification_en = ustrregexra(classification_en, "^sipil jalan dan jembatan$","civil roads and bridges")
		replace classification_en = "\parbox{0.25\textwidth}{" + classification_en + "\\[-3mm]}" if _n > 2
		replace classification = "\parbox{0.25\textwidth}{" + classification + "\\[-3mm]}" if _n > 2
		replace classification = "\hspace{-.4cm} Detailed components" if _n == 2
		replace classification_en = "\hspace{-1.2cm}(Top 10)" if _n == 2

		label var classification_en "Type of Work"
		keep if _n < 13
		compress
		order blank classification classification_en N_str share Amount_str Amount_R_str	
		export delimited using temp.csv, replace novarnames
		/*Table OA.1: Indonesia*/
		python script "tably.py", args(temp.csv -ero ../Output/TableOA1.tex -a lrrrr -c "Indonesia (Construction)" -n -f)
		sleep 1000
		erase temp.csv
	restore

	
	
	rename (z_all_pds z_num_np_bids)(reserve N_bids)
	cap drop temp 
	gen temp = z_bid if z_bid_rank == 1
	bys contract_id: egen lowbid = max(temp)
	cap drop temp
	bys contract_id: egen winbid = max(win_bid)
	qui gen win_bid_pct = winbid / reserve
	qui gen low_bid_pct = lowbid / reserve
	qui bys firm_id: gen N_participations = _N
	qui gen reserve_thd = reserve / 1000000
	qui gen winbid_thd = winbid / 1000000
	qui gen lowbid_thd = lowbid / 1000000
	qui egen totalcontractamt = total(winbid * winner)
	qui gen est_mil = .

/* Table 2: Summary Statistics: Public Works Auctions in Indonesia */	
	varlabeling_unification "indonesia"
	foreach type in "Electronic" "Manual" "All"{
		preserve
			if "`type'" == "Electronic"{
				keep if z_proc_type == "SEP"
			}	
			else if "`type'" == "Manual"{
				keep if z_proc_type == "CTI"
			}	
	/* by Auctions*/
			estpost sum lowbid_thd 
				est store `type'1a
			estpost sum N_bids 
				est store `type'1b
			estpost sum reserve_thd  
				est store `type'1c
			estpost sum low_bid_pct  
				est store `type'1d
		restore
	}

	/* by Bidders*/
	estpost sum N_participations N_won mean_blog30 mean_blog60 mean_blog90 mean_blog120 mean_lnblog30 mean_lnblog60 mean_lnblog90 mean_lnblog120 
	est store bybidder
	estout All1a Electronic1a Manual1a using ../Output/Table2.tex, ///
		cells("mean(fmt(%09.0fc)) a(v(\raisebox{-2.2mm}[0mm][0mm]{))&count(fmt(%9.0gc))&b(v(}))" ///
		"sd(par fmt(%9.0fc)) .") label replace collabels(none) style(tex) mlabels(,none)
	estout All1b Electronic1b Manual1b using ../Output/Table2.tex, ///
		cells("mean(fmt(%09.3fc)) a(v(\raisebox{-2.2mm}[0mm][0mm]{))&count(fmt(%9.0gc))&b(v(}))" ///
		"sd(par fmt(%9.3fc)) .") label append collabels(none) style(tex) mlabels(,none)
	estout All1c Electronic1c Manual1c using ../Output/Table2.tex, ///
		cells("mean(fmt(%09.0fc)) a(v(\raisebox{-2.2mm}[0mm][0mm]{))&count(fmt(%9.0gc))&b(v(}))" ///
		"sd(par fmt(%9.0fc)) .") label append collabels(none) style(tex) mlabels(,none)
	estout All1d Electronic1d Manual1d using ../Output/Table2.tex, ///
		cells("mean(fmt(%09.3fc)) a(v(\raisebox{-2.2mm}[0mm][0mm]{))&count(fmt(%9.0gc))&b(v(}))" ///
		"sd(par fmt(%9.3fc)) .") label append collabels(none) style(tex) mlabels(,none)
		
	estout bybidder using ../Output/Table2.tex, ///
			title("\hline\\[-2mm] &\multicolumn{6}{c}{By Bidders}\\[1mm]&&&Mean&Obs.\\[1mm]\hline") ///
			cells("k0(v(&&\multicolumn{1}{c}{))&mean(fmt(%09.3fc))&k1(v(})) a(v(\multicolumn{1}{c}{\raisebox{-2.2mm}[0mm][0mm]{))&count(fmt(%9.0gc))&b(v(}}))" ///
			"k0(v(&&\multicolumn{1}{c}{))&sd(par fmt(%9.2fc))&k1(v(})) .")  ///
			label append collabels(none) style(tex) mlabels(,none) 

	rename delta delta_low1
	
/*Figure OE.1: Indonesia, Running Variables */
	cap graph drop _all
	hist delta_low1 if abs(delta_low1) < .02 & delta_low1 != 0 , bin(150) color(gs11) ///
		name(indonesia_main) xtitle({&Delta}) graphregion(color(white) lcolor(none)) ///
		ylabel(/*0(.2)1*/, angle(0) format(%3.1g)) title(All) 
		count if delta_low1 == 0
		*the fraction of tied auction is 0.04 % (4/(4+9382))  
		
	hist delta_low1 if abs(delta_low1) < .02 & z_proc_type == "CTI" & delta_low1 != 0 , bin(150) color(gs11) ///
		name(indonesia_pp) xtitle({&Delta}) graphregion(color(white) lcolor(none)) ///
		ylabel(/*0(.2)1*/, angle(0) format(%3.1g)) title(Paper Based) 
		count if delta_low1 == 0 & z_proc_type == "CTI"
	
	hist delta_low1 if abs(delta_low1) < .02 & z_proc_type == "SEP" & delta_low1 != 0 , bin(150) color(gs11) ///
		name(indonesia_ep) xtitle({&Delta}) graphregion(color(white) lcolor(none)) ///
		ylabel(/*0(.2)1*/, angle(0) format(%3.1g)) title(E-Procurement)
		count if delta_low1 == 0 & z_proc_type == "SEP"
		
	graph combine indonesia_main indonesia_pp indonesia_ep, ///
		cols(1) xsize(2) ysize(4) scale(.85) graphregion(color(white) lcolor(none))
	graph export ../Output/FigureOE1.png, replace

/* Other 4 buyers */
est clear
do "procurement_type_classification.do"
foreach buyer in "georgia" "caltrans"  "malta" "mongolia" {
	di as result "************************* `buyer' *************************"
	if "`buyer'" == "caltrans"{
		use ../Data/caltrans/sample_caltrans29Dec24.dta, clear
		gen reserve = .
		rename pct_winbid win_bid_pct 
		rename lowbid lowbid_original
		bys firm_id: gen N_participations = _N
		rename bid_rank bid_rank_original
		rename bid_rank_rd bid_rank
		/* whether comparison amount is recorded in the source pdf*/
		/*gen c = (record_compari != "") 
		. tab year c
				   |           c
			  year |         0          1 |     Total
		-----------+----------------------+----------
			  2014 |     2,551         32 |     2,583 
			  2015 |     2,647         49 |     2,696 
			  2016 |     2,382         31 |     2,413 
			  2017 |     2,124         15 |     2,139 
			  2018 |     2,500         36 |     2,536 
			  2019 |     2,382         50 |     2,432 
			  2020 |     1,505         28 |     1,533 
		-----------+----------------------+----------
			 Total |    16,091        241 |    16,332 
		*/
		
		*add Jun 18, 2024 
		qui gen delta_low1 = delta
		cap graph drop California
		hist delta_low1 if abs(delta_low1) < .02 & delta_low1 != 0, bin(150) color(gs11) ///
		name(California) xtitle({&Delta}) graphregion(color(white) lcolor(none)) ///
		ylabel(/*0(.2)1*/, angle(0) format(%3.1g)) title(California) 
		count if delta_low1 == 0 
		*the fraction of tied auctions is 0%.  
		

		preserve
		/* Type of Projects: California */
			keep if bid_rank == 1
			bysort type : gen N_procurement = _N
			egen total_number_contracts = total(bid_rank == 1) 
			egen total_contract_amount = total(winbid) 
			egen tag_procurement = tag(type)
			keep if tag_procurement == 1
			gsort -N_procurement
			order type N_procurement

			
			gen share = "(" + strofreal(100, "%6.1f") + "\%)"
			gen N_str = strofreal(total_number_contracts, "%9.0gc")
			gen Amount_R_str = "(" + strofreal(100, "%6.1f")+"\%)"
			gen Amount_str = strofreal(round(total_contract_amount/1000000), "%9.0gc")
			keep if _n == 1
			gen contract = "Work"
			keep contract N_str share Amount_str Amount_R_str
			order contract N_str share Amount_str Amount_R_str
			export delimited using temp.csv, replace novarnames
		/*Table OB.1: California*/
			python script "tably.py", args(temp.csv -ero ../Output/TableOB1_California.tex -a lrrrr -c "California" -n -f)
			sleep 500
			erase temp.csv
		restore
	 
	}
	else if "`buyer'" == "georgia"{
		use ../Data/georgia/sample_georgia26may22.dta, clear
		rename est reserve
		rename pct_winbid win_bid_pct 
		rename bid_rank_first bid_rank
		rename bid_first bid
		gen est = .		
		
		qui gen delta_low1 = pdelta_first
		cap graph drop Georgia
		hist delta_low1 if abs(delta_low1) < .02 & delta_low1 != 0, bin(150) color(gs11) ///
		name(Georgia) xtitle({&Delta}) graphregion(color(white) lcolor(none)) ///
		ylabel(/*0(.2)1*/, angle(0) format(%10.1g)) title(Georgia) 
		count if delta_low1 == 0 
		*the fraction of tied auctions is 6.64% (=2804/(2804+39434)
		
		preserve
		/* Type of Projects: Georgia */
			keep if bid_rank == 1 & bid < .
			qui egen contract_tg = tag(contract_id)
			qui keep if contract_tg == 1
			gen total_number_contracts = _N
			egen total_contract_amount = total(bid) 
			bysort procuringcategory : gen N_cpv = _N
			bysort procuringcategory : egen Amount_cpv = total(bid) 
			egen tag_cpv = tag(procuringcategory)
			keep if tag_cpv == 1
			gen cpv_R = N_cpv / total_number_contracts
			standardize_Procurement_Type "georgia"
			
			egen N_work = total(N_cpv) if construction == 1
			egen N_service = total(N_cpv) if services == 1
			egen N_supply = total(N_cpv) if supplies == 1

			gsort -Procurement_Type -N_cpv
			egen N = rowtotal(N_work N_service N_supply)
			gen classification_R = N / total_number_contracts
			bysort Procurement_Type: egen Amount = total(Amount_cpv)
			gen Amount_R = Amount / total_contract_amount
			egen classification_T = tag(Procurement_Type)
			keep if classification_T ==1
			drop classification_T
			replace Procurement_Type = "\parbox{0.3\textwidth}{" + Procurement_Type + "\\[-3mm]}" if Procurement_Type != ""
			
			gsort -Procurement_Type
			insobs 1
			foreach v in "N" "Amount" "Amount_R" "classification_R" {
				tempvar tempv002
				qui egen `tempv002' = total(`v')
				replace `v' = `tempv002' if `v' == .
			}
			qui count
			qui replace Procurement_Type = "Total" if _n == `r(N)'
			
			gen share = "(" + strofreal(classification_R * 100, "%6.1f") + "\%)"
			gen N_str = strofreal(N, "%9.0gc")
			gen Amount_R_str = "(" + strofreal(Amount_R * 100, "%6.1f")+"\%)"
			gen Amount_str = strofreal(round(Amount/1000000), "%9.0gc")
			
			order Procurement_Type  N_str share Amount_str Amount_R_str
			keep Procurement_Type share N_str Amount_str Amount_R_str

			compress
			export delimited using temp.csv, replace novarnames
			/*Table OB.1: Georgia*/
			python script "tably.py", args(temp.csv -ero ../Output/TableOB1_Georgia.tex -a lrrrr -c "Georgia" -n -f)
			sleep 500
			erase temp.csv
		restore
				
		
	}
	else if "`buyer'" == "mongolia"{
	    use ../Data/mongolia/sample_mongolia_30jun22.dta, clear
		/* 17sep2018 - 9mar22 */
		gen reserve = .
		gen win_bid_pct = .
		replace winbid = winbid / 1000000
		replace reserve = reserve / 1000000
		gen est = .
		qui gen delta_low1 = delta1
		cap graph drop Mongolia
		hist delta_low1 if abs(delta_low1) < .02 & delta_low1 != 0, bin(150) color(gs11) ///
		name(Mongolia) xtitle({&Delta}) graphregion(color(white) lcolor(none)) ///
		ylabel(/*0(.2)1*/, angle(0) format(%10.1g)) title(Mongolia) 
		count if delta_low1 == 0 
		*the fraction of tied auction is 2.46% (=1507/(1507+59832))
		
		* added on Aug 10, 2024
		preserve
		/* Type of Projects: Mongolia */	
			keep if bid_rank == 1 & bid < .
			qui egen contract_tg = tag(contract_id)
			qui keep if contract_tg == 1
			qui gen total_number_contracts = _N
			egen total_contract_amount = total(bid) 
			bysort contract : gen N = _N
			bysort contract: egen Amount = total(bid)
			gen classification_R = N / total_number_contracts
			gen Amount_R = Amount / total_contract_amount
			egen tag_procurement = tag(contract)
			keep if tag_procurement == 1

			standardize_Procurement_Type "mongolia"
			gen index0 = 1
			replace index0 = 2 if ustrregexm(Procurement_Type , "Supplies")
			replace index0 = 3 if ustrregexm(Procurement_Type,"Services \(Consulting\)")
			replace index0 = 4 if ustrregexm(Procurement_Type , "Services \(Other\)")
			replace index0 = 5 if ustrregexm(Procurement_Type , "Mining license")
			
			sort index0
			insobs 1
			foreach v in "N" "Amount" "Amount_R" "classification_R" {
				tempvar tempv002
				qui egen `tempv002' = total(`v')
				replace `v' = `tempv002' if `v' == .
			}
			qui count
			qui replace Procurement_Type = "Total" if _n == `r(N)'
			gen share = "("+strofreal(classification_R * 100, "%6.1f")+"\%)"
			gen Amount_R_str = "("+strofreal(Amount_R * 100, "%6.1f")+"\%)"
			gen N_str = strofreal(N, "%9.0gc")
			gen Amount_str = strofreal(round(Amount/1000000000), "%12.0gc")
			
			keep Procurement_Type share N_str Amount_str Amount_R_str index0
			compress
			order Procurement_Type N_str share Amount_str Amount_R_str
			drop index0
			export delimited using temp.csv, replace novarnames
			/*Table OB.1: Mongolia*/
			python script "tably.py", args(temp.csv -ero ../Output/TableOB1_Mongolia.tex -a lrrrr -c "Mongolia" -n -f)
			sleep 500
			erase temp.csv
		restore		
	}
	
	else if "`buyer'" == "malta"{
	    use ../Data/malta/malta.dta, clear
		keep if Evaluation_Method == "Price/Cost Effectiveness" & eAuctions=="No"
		gen reserve = .
		gen win_bid_pct = .
		qui bys firm_id: gen N_participations = _N
		qui bys contract_id: gen N_bids = _N
		sort contract_id winbid
		gen est = .
		
		qui gen delta_low1 = delta
		cap graph drop Malta
		hist delta_low1 if abs(delta_low1) < .02  & delta_low1 != 0, bin(150) color(gs11) ///
		name(Malta) xtitle({&Delta}) graphregion(color(white) lcolor(none)) ///
		ylabel(/*0(.2)1*/, angle(0) format(%10.1g)) title(Malta)  
		count if delta_low1 == 0 
		*the fraction of tied auction is 0%. 
			
		preserve
		/* Type of Projects: Malta */
			rename CPV_Codes cpv
			keep if bid_rank == 1 & bid < .
			qui egen contract_tg = tag(contract_id)
			qui keep if contract_tg == 1
			qui gen total_number_contracts = _N
			egen total_contract_amount = total(bid) 
			bysort cpv : gen N_cpv = _N
			bysort Procurement_Type: gen N = _N
			bysort Procurement_Type: egen Amount = total(bid)
			egen tag_cpv = tag(cpv)
			keep if tag_cpv == 1
			egen tag_procuring_type = tag(Procurement_Type)
			gen cpv_R = N_cpv / total_number_contracts
			gen classification_R = N / total_number_contracts
			gen Amount_R = Amount / total_contract_amount
			keep if tag_procuring_type == 1			
			gsort -Procurement_Type
			insobs 1
			foreach v in "N" "Amount" "Amount_R" "classification_R" {
				tempvar tempv002
				qui egen `tempv002' = total(`v')
				replace `v' = `tempv002' if `v' == .
			}
			qui count
			qui replace Procurement_Type = "Total" if _n == `r(N)'
			qui gen share = "("+strofreal(classification_R* 100, "%6.1f")+"\%)"
			gen Amount_R_str = "("+strofreal(Amount_R * 100, "%6.1f")+"\%)"
			gen N_str = strofreal(N, "%9.0gc")
			gen Amount_str = strofreal(round(Amount/1000), "%10.0gc")
			replace Procurement_Type = "\parbox{0.3\textwidth}{" + Procurement_Type + "\\[-3mm]}" if cpv != ""
			keep Procurement_Type share N_str Amount_str Amount_R_str
			order Procurement_Type N_str share  Amount_str Amount_R_str
			compress
			export delimited using temp.csv, replace novarnames
			/*Table OB.1: Malta*/
			python script "tably.py", args(temp.csv -ero ../Output/TableOB1_Malta.tex -a lrrrr -c "Malta" -n -f)
			sleep 1000
			erase temp.csv
			
		restore
			

	}
	bys contract_id: replace winbid = winbid[_n - 1] if winbid[_n - 1] < .
	bys contract_id: replace win_bid_pct = win_bid_pct[_n - 1] if win_bid_pct[_n - 1] < .
	
	/* lowest bid*/
	tempvar tempv 
	gen `tempv' = bid if bid_rank == 1
	bys contract_id: egen lowbid = max(`tempv')
	
	gen reserve_thd = reserve / 1000
	gen winbid_thd = winbid / 1000
	gen lowbid_thd = lowbid / 1000
	if "`buyer'" == "mongolia"{
	    replace lowbid_thd = lowbid_thd / 1000000
	}
	else if "`buyer'" == "caltrans"{
	    replace lowbid_thd = lowbid_thd / 1000

	}
	gen est_mil = est / 1000000

	egen totalcontractamt = total(winbid * winner)
	bys firm_id: egen Share = total(winbid / totalcontractamt)					
	varlabeling_unification "`buyer'"

	
	/* summary stats: 4 countries*/	
	/* by Auctions*/
	estpost sum lowbid_thd 
		est store `buyer'1a
	estpost sum N_bids 
		est store `buyer'1b
	cap estpost sum reserve_thd  
	cap est store `buyer'1c
	*if "`buyer'" == "caltrans"{
	cap estpost sum est_mil
	cap est store `buyer'1d
	*}
	/* by Bidders*/
	estpost sum N_participations N_won mean_blog30 mean_blog60 mean_blog90 mean_blog120
		est store `buyer'2
			
}


local preRB = "a(v(\raisebox{-2.2mm}[0mm][0mm]{))"
local pstRB = "b(v(}))"
local RBa = "\raisebox{-2.2mm}[0mm][0mm]{"


estout georgia1a mongolia1a malta1a caltrans1a using ../Output/Table7.tex, ///
	cells("mean(fmt(%9.2fc)) `preRB'&count(fmt(%9.0gc))&`pstRB'" ///
	"sd(par fmt(%9.2fc)) .") label replace collabels(none) style(tex) mlabels(,none)
estout georgia1b mongolia1b malta1b caltrans1b using ../Output/Table7.tex, ///
	cells("mean(fmt(%9.2fc)) `preRB'&count(fmt(%8.0gc))&`pstRB'" ///
	"sd(par fmt(%9.2fc)) .") label append collabels(none) style(tex) mlabels(,none)
estout georgia1c /*caltrans1c malta1c mongolia1c*/ using ../Output/Table7.tex, ///
	cells("mean(fmt(%9.2fc)) a(v(`RBa'))&count(fmt(%9.0gc))&b(v(}&-&`RBa'-}&-&`RBa'-}&-&`RBa'-}))" ///
	"sd(par fmt(%9.2fc)) .&d(v(&(  -  )&&(  -  )&&(  -  )&)) ") label append collabels(none) style(tex) mlabels(,none)
estout /*georgia1c*/ caltrans1d /*malta1c mongolia1c*/ using ../Output/Table7.tex, ///
	cells("c(v(-&`RBa'-}&-&`RBa'-}&-&`RBa'-}&))& mean(fmt(%9.2fc)) a(v(`RBa'))&count(fmt(%9.0gc))&b(v(}))" ///
	"c(v((  -  )&&(  -  )&&(  -  )&&))& sd(par fmt(%9.2fc)) . &d(v()) ") label append collabels(none) style(tex) mlabels(,none)
	
estout georgia2 caltrans2 malta2 mongolia2 using ../Output/Table7.tex, ///
		title("\ \\[-2mm]\hline &\multicolumn{8}{c}{By Bidders}\\[1mm]") ///
		cells("mean(fmt(%9.2fc)) a(v(\raisebox{-2.2mm}[0mm][0mm]{))&count(fmt(%9.0gc))&b(v(}))" ///
		"sd(par fmt(%9.2fc)) .")  ///
		label append collabels(none) style(tex) mlabels(,none) 
	
/*Figure OI.1: Histogram of the Running Variable */
	graph combine California Georgia Mongolia Malta, ///
		cols(2) xsize(4) ysize(4) scale(.75) graphregion(color(white) lcolor(none))
	graph export ../Output/FigureOI1.png, replace
	
		


			